package com.dingwen.treasure.jpa.dao;

import com.dingwen.treasure.model.entity.jpa.QuartzInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * 定时任务信息 dao
 * //TODO 动态更新
 * @author dingwen
 * @date 2022/03/13
 */
@Repository
public interface QuartzInfoDao extends JpaRepository<QuartzInfo, Long>, QuerydslPredicateExecutor<QuartzInfo> {
    /**
     * 成功增量
     *
     * @param id 定时任务id
     */
    @Modifying
    @Query(value = "update quartz_info set success = success + 1, update_time = now() where id =:id", nativeQuery = true)
    void incrementForSuccess(@Param("id") Long id);

    /**
     * 失败增量
     *
     * @param id 定时任务id
     */
    @Modifying
    @Query(value = "update quartz_info set fail = fail + 1, update_time = now()  where id =:id", nativeQuery = true)
    void incrementForFail(@Param("id") Long id);
}
